package cn.stronglink.esm27.collection.iot.devices.esm27.task;

import java.util.TimerTask;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import cn.stronglink.esm27.collection.iot.devices.esm27.ESM27Server;
import cn.stronglink.esm27.collection.iot.devices.esm27.request.entity.ESM27RequestMessageFactory;

public class PushGasTimer extends TimerTask {
	private static Logger logger = LogManager.getLogger(PushGasTimer.class.getName());
	private ESM27Server esm27Server; // esm27服务器
	private byte deviceCode;
	
	public PushGasTimer(ESM27Server server,byte deviceCode) {
		this.esm27Server=server;
		this.deviceCode=deviceCode;
	}

	@Override
	public void run() {
		try {
			if (esm27Server.isConnection()) {
				byte[] datas = ESM27RequestMessageFactory.createMessage(deviceCode, (byte) 0x0A, null);
				esm27Server.send(datas);
				logger.info("定时获取气体实时数据命令已发送");
			}
		} catch (Exception e) {
			logger.error(e);
		}
	}

}
